<!DOCTYPE html>
<html lang="cn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>proxy</title>
</head>
<body>
  <div id="app">
    hello
  </div>
  <script>
    let data = {
      message: '' 
    } 

     //模拟vue实例；
    // const p = new Proxy(target,handler);
    //  handler一个通常以函数作为属性的对象，各属性中的函数分别定义了在执行各种操作时代理 p 的行为。

    let vm = new Proxy(data ,{
      get (target,key) {
        console.log('get ',key,target[key]);
        return target[key]
      } ,
      set (target, key, newValue) {
        console.log('set key:',key, newValue);
        if(newValue == target[key]) {
          return 
        }

        target[key] = newValue ;
        document.querySelector('#app').textContent = target[key] ;

      }

    })

    
    
    vm.message = 'hello word' ;
    console.log(vm.message);


  </script>
</body>
</html>